package com.wenyl.interview.redis.controller;

import com.wenyl.interview.redis.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Swimming Dragon
 * @description: TODO
 * @date 2024年09月25日 23:07
 */
@RestController
@RequestMapping("/goods")
public class GoodsController {
    @Autowired
    private IGoodsService goodsService;
    /**
     * 缓存击穿演示
     * @param goodsId 商品IO
     * @return 商品信息
     */
    @GetMapping("/getById/{goodsId}")
    public String getById(@PathVariable(value = "goodsId") String goodsId){
        return goodsService.getById(goodsId);
    }
    /**
     * 缓存击穿互斥锁解决
     * @param goodsId 商品IO
     * @return 商品信息
     */
    @GetMapping("/getByIdv2/{goodsId}")
    public String getByIdv2(@PathVariable(value = "goodsId") String goodsId){
        return goodsService.getByIdv2(goodsId);
    }
    /**
     * 缓存击穿逻辑过期解决
     * @param goodsId 商品IO
     * @return 商品信息
     */
    @GetMapping("/getByIdv3/{goodsId}")
    public String getByIdv3(@PathVariable(value = "goodsId") String goodsId){
        return goodsService.getByIdv3(goodsId);
    }
}
